Attribute VB_Name = "ModSubClassing"
Option Explicit

Public lpPrevWP As Long
Public boolDWMDEF As Long
Public rcSubClassing As RECT
Public rcClient As RECT
Public LRESULT As Long

Public Sub SubClass(ByVal hwnd As Long)
lpPrevWP = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf myWP)
'force the window to send a WM_NCCALCSIZE messgae
GetWindowRect hwnd, rcSubClassing
SetWindowPos hwnd, 0, rcSubClassing.Left, rcSubClassing.Top, rcSubClassing.Right - rcSubClassing.Left, _
rcSubClassing.Bottom - rcSubClassing.Top, SWP_FRAMECHANGED
End Sub

Public Function myWP(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

If uMsg = WM_NCCALCSIZE And wParam > 0 Then
myWP = 0
'myWP = CallWindowProc(lpPrevWP, hwnd, uMsg, wParam, lParam)
ElseIf uMsg = WM_SIZING Then
Call CopyMemory(rcClient, ByVal lParam, Len(rcClient))

FrmMain.FrameUI.Width = (rcClient.Right - rcClient.Left) * Screen.TwipsPerPixelX
FrmMain.FrameUI.Height = (rcClient.Bottom - rcClient.Top) * Screen.TwipsPerPixelY
myWP = CallWindowProc(lpPrevWP, hwnd, uMsg, wParam, lParam)

Else
boolDWMDEF = DwmDefWindowProc(hwnd, uMsg, wParam, lParam, LRESULT)
If boolDWMDEF Then
    myWP = LRESULT
Else
    myWP = CallWindowProc(lpPrevWP, hwnd, uMsg, wParam, lParam)
End If

End If

End Function
